package com.ruoyi.yuangong.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yuangong.domain.Qiandaoguanli;
import com.ruoyi.yuangong.service.IQiandaoguanliService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * qiandaoController
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Controller
@RequestMapping("/yuangong/qiandao")
public class QiandaoguanliController extends BaseController {
    private final String prefix = "yuangong/qiandao";

    @Autowired
    private IQiandaoguanliService qiandaoguanliService;

    @RequiresPermissions("yuangong:qiandao:view")
    @GetMapping()
    public String qiandao () {
        return prefix + "/qiandao";
    }

    /**
     * 查询qiandao列表
     */
    @RequiresPermissions("yuangong:qiandao:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list (Qiandaoguanli qiandaoguanli) {
        startPage();
        List<Qiandaoguanli> list = qiandaoguanliService.selectQiandaoguanliList(qiandaoguanli);
        return getDataTable(list);
    }

    /**
     * 导出qiandao列表
     */
    @RequiresPermissions("yuangong:qiandao:export")
    @Log(title = "qiandao", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export (Qiandaoguanli qiandaoguanli) {
        List<Qiandaoguanli> list = qiandaoguanliService.selectQiandaoguanliList(qiandaoguanli);
        ExcelUtil<Qiandaoguanli> util = new ExcelUtil<Qiandaoguanli>(Qiandaoguanli.class);
        return util.exportExcel(list, "qiandao数据");
    }

    /**
     * 新增qiandao
     */
    @GetMapping("/add")
    public String add () {
        return prefix + "/add";
    }

    /**
     * 新增保存qiandao
     */
    @RequiresPermissions("yuangong:qiandao:add")
    @Log(title = "qiandao", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave (Qiandaoguanli qiandaoguanli) {
        return toAjax(qiandaoguanliService.insertQiandaoguanli(qiandaoguanli));
    }

    /**
     * 修改qiandao
     */
    @RequiresPermissions("yuangong:qiandao:edit")
    @GetMapping("/edit/{id}")
    public String edit (@PathVariable("id") Integer id, ModelMap mmap) {
        Qiandaoguanli qiandaoguanli =
                qiandaoguanliService.selectQiandaoguanliById(id);
        mmap.put("qiandaoguanli", qiandaoguanli);
        return prefix + "/edit";
    }

    /**
     * 修改保存qiandao
     */
    @RequiresPermissions("yuangong:qiandao:edit")
    @Log(title = "qiandao", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave (Qiandaoguanli qiandaoguanli) {
        return toAjax(qiandaoguanliService.updateQiandaoguanli(qiandaoguanli));
    }

    /**
     * 删除qiandao
     */
    @RequiresPermissions("yuangong:qiandao:remove")
    @Log(title = "qiandao", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove (String ids) {
        return toAjax(qiandaoguanliService.deleteQiandaoguanliByIds(ids));
    }
}
